#include "stdafx.h"
#include <CommDlg.h>
#include "UserInterface.h"



int UserInterface::Full3dLungPosition_[4];
int UserInterface::CTSlicesPosition_[4];
int UserInterface::BronchialTreePosition_[4];
int UserInterface::DynamicLungPosition_[4];
int UserInterface::PlayButtonPosition_[6];
int UserInterface::PauseButtonPosition_[6];
int UserInterface::BackButtonPosition_[4];
int UserInterface::NextButtonPosition_[4];
int UserInterface::FileButtonPosition_[4];
int UserInterface::FileMenuPosition_[4];
int UserInterface::UpButtonPosition_[4];
int UserInterface::DownButtonPosition_[4];
int UserInterface::HelpButtonPosition_[4];
int UserInterface::HelpMenuPosition_[4];

HWND UserInterface::hwnd;
HINSTANCE UserInterface::hInst;

void UserInterface::CreateUserInterface (GLuint text)
{

	//if (texture_loaded==false) {
	//UserInterface::LoadGLTextures();
	//}
	glBindTexture(GL_TEXTURE_2D, text); 
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 

	UserInterface::Full3dLung_position(Full3dLungPosition_);
	UserInterface::CTSlices_position(CTSlicesPosition_);
	UserInterface::BronchialTree_position(BronchialTreePosition_);
	UserInterface::DynamicLung_position(DynamicLungPosition_);
	UserInterface::PlayButton_position(PlayButtonPosition_);
	UserInterface::PauseButton_position(PauseButtonPosition_);
	UserInterface::BackButton_position(BackButtonPosition_);
	UserInterface::NextButton_position(NextButtonPosition_);
	UserInterface::UpButton_position(UpButtonPosition_);
	UserInterface::DownButton_position(DownButtonPosition_);
	UserInterface::FileButton_position(FileButtonPosition_);
	UserInterface::FileMenu_position(FileMenuPosition_);
	UserInterface::HelpButton_position(HelpButtonPosition_);
	UserInterface::HelpMenu_position(HelpMenuPosition_);
	UserInterface::ScrollingBar_position(ScrollingBarVertical_);
	UserInterface::OtherDecoration();
}

void UserInterface::CreateVariableUserInterface()
{
	Full3dLungPosition_[0]=820; //left
	Full3dLungPosition_[1]=165;	//top
	Full3dLungPosition_[2]=955;	//right
	Full3dLungPosition_[3]=215;	//bottom

	CTSlicesPosition_[0]=820;	//left
	CTSlicesPosition_[1]=335;	//top
	CTSlicesPosition_[2]=955;	//right
	CTSlicesPosition_[3]=385;	//bottom

	BronchialTreePosition_[0]=820; //left
	BronchialTreePosition_[1]=505;	//top
	BronchialTreePosition_[2]=955;	//right
	BronchialTreePosition_[3]=555;	//bottom

	DynamicLungPosition_[0]=820;	//left
	DynamicLungPosition_[1]=675;	//top
	DynamicLungPosition_[2]=955;	//right
	DynamicLungPosition_[3]=725;	//bottom

	PlayButtonPosition_[0]=124;	//left
	PlayButtonPosition_[1]=669;	//top
	PlayButtonPosition_[2]=192;	//right
	PlayButtonPosition_[3]=724;	//bottom
	PlayButtonPosition_[4]=158;	//center-x
	PlayButtonPosition_[5]=696;	//center-y

	PauseButtonPosition_[0]=200;	//left
	PauseButtonPosition_[1]=669;	//top
	PauseButtonPosition_[2]=274;	//right
	PauseButtonPosition_[3]=724;	//bottom
	PauseButtonPosition_[4]=237;	//center-x
	PauseButtonPosition_[5]=696;	//center-y
	
	BackButtonPosition_[0]=395;	//left
	BackButtonPosition_[1]=676;	//top
	BackButtonPosition_[2]=448;	//right
	BackButtonPosition_[3]=718;	//bottom
	
	NextButtonPosition_[0]=512;	//left
	NextButtonPosition_[1]=676;	//top
	NextButtonPosition_[2]=565;	//right
	NextButtonPosition_[3]=718;	//bottom

	UpButtonPosition_[0]=460;	//left
	UpButtonPosition_[1]=649;	//top
	UpButtonPosition_[2]=500;	//right
	UpButtonPosition_[3]=692;	//bottom

	DownButtonPosition_[0]=460;	//left
	DownButtonPosition_[1]=701;	//top
	DownButtonPosition_[2]=500;	//right
	DownButtonPosition_[3]=746;	//bottom

	FileButtonPosition_[0]=0;	//left
	FileButtonPosition_[1]=0;	//top
	FileButtonPosition_[2]=147;	//right
	FileButtonPosition_[3]=30;	//bottom

	FileMenuPosition_[0]=0;		//left
	FileMenuPosition_[1]=30;	//top
	FileMenuPosition_[2]=147;	//right
	FileMenuPosition_[3]=159;	//bottom
	
	HelpButtonPosition_[0]=147;	//left
	HelpButtonPosition_[1]=0;	//top
	HelpButtonPosition_[2]=280;	//right
	HelpButtonPosition_[3]=30;	//bottom

	HelpMenuPosition_[0]=147;		//left
	HelpMenuPosition_[1]=30;	//top
	HelpMenuPosition_[2]=280;	//right
	HelpMenuPosition_[3]=80;	//bottom
}

UserInterface::~UserInterface ()
{

}

//int UserInterface::LoadGLTextures()                                    // Load Bitmaps And Convert To Textures 
//{ 
//    /* load an image file directly as a new OpenGL texture */
//    texture = SOIL_load_OGL_texture 
//        ( 
//        "Pics/UI.png", 
//        SOIL_LOAD_AUTO, 
//        SOIL_CREATE_NEW_ID, 
//        SOIL_FLAG_INVERT_Y 
//        ); 
//  
//    if(texture[0] == 0) 
//        return false; 
//  
//  
//    // Typical Texture Generation Using Data From The Bitmap 
//    glBindTexture(GL_TEXTURE_2D, texture[0]); 
//    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 
//    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 
//  
//    return true;                                        // Return Success 
//} 


void UserInterface::OtherDecoration()
{
	int position[4];
	position[0]=800;	//left
	position[2]=970;	//right

	position[1]=46;		//top
	position[3]=165;	//bottom
	glBegin(GL_QUADS);
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[0],position[3]); 
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[0],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[2],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[2],position[3]);
	glEnd();
	
	position[1]=206;	//top
	position[3]=334;	//bottom
	glBegin(GL_QUADS);
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[0],position[3]); 
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[0],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[2],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[2],position[3]);
	glEnd();

	position[1]=386;	//top
	position[3]=503;	//bottom
	glBegin(GL_QUADS);
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[0],position[3]); 
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[0],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[2],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[2],position[3]);
	glEnd();

	position[1]=555;	//top
	position[3]=673;	//bottom
	glBegin(GL_QUADS);
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[0],position[3]); 
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[0],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[2],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[2],position[3]);
	glEnd();

	position[0]=280;	//left
	position[1]=0;		//top
	position[2]=1024;	//right
	position[3]=30;		//bottom
	glBegin(GL_QUADS);
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[0],position[3]); 
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[0],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[2],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[2],position[3]);
	glEnd();
}




void UserInterface::Full3dLung_position(int* position) //JTexture* pTexture, int x0, int y0, int x1, int y1, int x2, int y2)
{
	
	glBegin(GL_QUADS);
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[0],position[3]); 
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[0],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[2],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[2],position[3]);
	glEnd();
	
}

void UserInterface::Full3dLung_check(int mouseX, int mouseY, LeoGraphics* leo)
{
	if (mouseX>=Full3dLungPosition_[0] && mouseX<=Full3dLungPosition_[2] &&
		mouseY>=Full3dLungPosition_[1] && mouseY<=Full3dLungPosition_[3])
	{
		UserInterface::Full3dLung_do(leo);
	}
}


void UserInterface::CTSlices_position(int* position) //JTexture* pTexture, int x0, int y0, int x1, int y1, int x2, int y2)
{
	
	glBegin(GL_QUADS);
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[0],position[3]); 
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[0],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[2],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[2],position[3]);
	glEnd();
	
}

void UserInterface::CTSlices_check(int mouseX, int mouseY, LeoGraphics* leo)
{
	if (mouseX>=CTSlicesPosition_[0] && mouseX<=CTSlicesPosition_[2] &&
		mouseY>=CTSlicesPosition_[1] && mouseY<=CTSlicesPosition_[3])
	{
		UserInterface::CTSlices_do(leo);
	}
}


void UserInterface::BronchialTree_position(int* position) //JTexture* pTexture, int x0, int y0, int x1, int y1, int x2, int y2)
{
	
	glBegin(GL_QUADS);
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[0],position[3]); 
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[0],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[2],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[2],position[3]);
	glEnd();
	
}
 
void UserInterface::BronchialTree_check(int mouseX, int mouseY, LeoGraphics* leo)
{
	if (mouseX>=BronchialTreePosition_[0] && mouseX<=BronchialTreePosition_[2] &&
		mouseY>=BronchialTreePosition_[1] && mouseY<=BronchialTreePosition_[3])
	{
		UserInterface::BronchialTree_do(leo);
	}
}


void UserInterface::DynamicLung_position(int* position) //JTexture* pTexture, int x0, int y0, int x1, int y1, int x2, int y2)
{
	
	glBegin(GL_QUADS);
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[0],position[3]); 
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[0],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[2],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[2],position[3]);
	glEnd();
	
}

void UserInterface::DynamicLung_check(int mouseX, int mouseY)
{
	if (mouseX>=DynamicLungPosition_[0] && mouseX<=DynamicLungPosition_[2] &&
		mouseY>=DynamicLungPosition_[1] && mouseY<=DynamicLungPosition_[3])
	{
		UserInterface::DynamicLung_do();
	}
}


void UserInterface::PlayButton_position(int* position) //JTexture* pTexture, int x0, int y0, int x1, int y1, int x2, int y2)
{
	
	glBegin(GL_QUADS);
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[0],position[3]); 
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[0],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[2],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[2],position[3]);
	glEnd();
	
}
 
void UserInterface::PlayButton_check(int mouseX, int mouseY, LeoGraphics* leo)
{
	int x_diff = mouseX-PlayButtonPosition_[4];
	int y_diff = mouseY-PlayButtonPosition_[5];
	int distance_square = x_diff*x_diff+y_diff*y_diff;
	int ray= PlayButtonPosition_[0]-PlayButtonPosition_[4];
	int ray_square=ray*ray;
	if (distance_square<=ray_square)
	{
		UserInterface::PlayButton_do(leo);
	}
}


void UserInterface::PauseButton_position(int* position) //JTexture* pTexture, int x0, int y0, int x1, int y1, int x2, int y2)
{
	
	glBegin(GL_QUADS);
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[0],position[3]); 
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[0],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[2],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[2],position[3]);
	glEnd();
	
}
 
void UserInterface::PauseButton_check(int mouseX, int mouseY, LeoGraphics* leo)
{
	int x_diff = mouseX-PauseButtonPosition_[4];
	int y_diff = mouseY-PauseButtonPosition_[5];
	int distance_square = x_diff*x_diff+y_diff*y_diff;
	int ray= PauseButtonPosition_[0]-PauseButtonPosition_[4];
	int ray_square=ray*ray;
	if (distance_square<=ray_square)
	{
		UserInterface::PauseButton_do(leo);
	}
}


void UserInterface::BackButton_position(int* position) //JTexture* pTexture, int x0, int y0, int x1, int y1, int x2, int y2)
{
	
	glBegin(GL_QUADS);
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[0],position[3]); 
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[0],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[2],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[2],position[3]);
	glEnd();
	
}

void UserInterface::BackButton_check(int mouseX, int mouseY, LeoGraphics* leo)
{
	if (mouseX>=BackButtonPosition_[0] && mouseX<=BackButtonPosition_[2] &&
		mouseY>=BackButtonPosition_[1] && mouseY<=BackButtonPosition_[3])
	{
		UserInterface::BackButton_do(leo);
	}
}


void UserInterface::NextButton_position(int* position) //JTexture* pTexture, int x0, int y0, int x1, int y1, int x2, int y2)
{
	
	glBegin(GL_QUADS);
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[0],position[3]); 
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[0],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[2],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[2],position[3]);
	glEnd();
	
}

void UserInterface::NextButton_check(int mouseX, int mouseY, LeoGraphics* leo)
{
	if (mouseX>=NextButtonPosition_[0] && mouseX<=NextButtonPosition_[2] &&
		mouseY>=NextButtonPosition_[1] && mouseY<=NextButtonPosition_[3])
	{
		UserInterface::NextButton_do(leo);
	}
}


void UserInterface::UpButton_position(int* position) //JTexture* pTexture, int x0, int y0, int x1, int y1, int x2, int y2)
{
	
	glBegin(GL_QUADS);
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[0],position[3]); 
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[0],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[2],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[2],position[3]);
	glEnd();
	
}

void UserInterface::UpButton_check(int mouseX, int mouseY, LeoGraphics* leo)
{
	if (mouseX>=UpButtonPosition_[0] && mouseX<=UpButtonPosition_[2] &&
		mouseY>=UpButtonPosition_[1] && mouseY<=UpButtonPosition_[3])
	{
		UserInterface::UpButton_do(leo);
	}
}


void UserInterface::DownButton_position(int* position) //JTexture* pTexture, int x0, int y0, int x1, int y1, int x2, int y2)
{
	
	glBegin(GL_QUADS);
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[0],position[3]); 
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[0],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[2],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[2],position[3]);
	glEnd();
	
}

void UserInterface::DownButton_check(int mouseX, int mouseY, LeoGraphics* leo)
{
	if (mouseX>=DownButtonPosition_[0] && mouseX<=DownButtonPosition_[2] &&
		mouseY>=DownButtonPosition_[1] && mouseY<=DownButtonPosition_[3])
	{
		UserInterface::DownButton_do(leo);
	}
}


void UserInterface::FileButton_position(int* position) //JTexture* pTexture, int x0, int y0, int x1, int y1, int x2, int y2)
{

	glBegin(GL_QUADS);
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[0],position[3]); 
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[0],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[2],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[2],position[3]);
	glEnd();
	
}

void UserInterface::FileButton_check(int mouseX, int mouseY)
{
	if (mouseX>=FileButtonPosition_[0] && mouseX<=FileButtonPosition_[2] &&
		mouseY>=FileButtonPosition_[1] && mouseY<=FileButtonPosition_[3])
	{
		UserInterface::FileButton_do();
	}
}


void UserInterface::FileMenu_position(int* position) //JTexture* pTexture, int x0, int y0, int x1, int y1, int x2, int y2)
{
	if (enableFileButton_==1)
	{
	glBegin(GL_QUADS);
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[0],position[3]); 
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[0],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[2],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[2],position[3]);
	glEnd();
	}
	
}


void UserInterface::HelpButton_position(int* position) //JTexture* pTexture, int x0, int y0, int x1, int y1, int x2, int y2)
{

	glBegin(GL_QUADS);
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[0],position[3]); 
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[0],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[2],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[2],position[3]);
	glEnd();
	
}

void UserInterface::HelpButton_check(int mouseX, int mouseY)
{
	if (mouseX>=HelpButtonPosition_[0] && mouseX<=HelpButtonPosition_[2] &&
		mouseY>=HelpButtonPosition_[1] && mouseY<=HelpButtonPosition_[3])
	{
		UserInterface::HelpButton_do();
	}
}


void UserInterface::HelpMenu_position(int* position) //JTexture* pTexture, int x0, int y0, int x1, int y1, int x2, int y2)
{
	if (enableHelpButton_==1)
	{
	glBegin(GL_QUADS);
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[0],position[3]); 
	glTexCoord2f((float)(position[0])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[0],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[1])/768.0f); glVertex2i(position[2],position[1]);
	glTexCoord2f((float)(position[2])/1024.0f, (float)(768.0f-position[3])/768.0f); glVertex2i(position[2],position[3]);
	glEnd();
	}
	
}


void UserInterface::ScrollingBar_position(int position)
{
	glBegin(GL_QUADS);
	glTexCoord2f(712.0f/1024.0f, (768.0f-250.0f)/768.0f); glVertex2i(695,position+7+45);
	glTexCoord2f(712.0f/1024.0f, (768.0f-240.0f)/768.0f); glVertex2i(695,position-7+45);
	glTexCoord2f(722.0f/1024.0f, (768.0f-240.0f)/768.0f); glVertex2i(730,position-7+45);
	glTexCoord2f(722.0f/1024.0f, (768.0f-250.0f)/768.0f); glVertex2i(730,position+7+45);
	glEnd();
}

int UserInterface::ScrollingBar_CheckInside(LPARAM lParam)
{
	int position = UserInterface::ScrollingBarVertical_;
	int x=LOWORD(lParam);
	int y=HIWORD(lParam);
	if (x>=695&&x<=730&&y>=52&&y<=624)
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}

void UserInterface::ScrollingBar_Move(LPARAM lParam)
{
	int y=HIWORD(lParam);
	if (y>=0 && y<=768)
	{
		if (y<=52)
		{
			y=52;
		}
		else if (y>=624)
		{
			y=624;
		}
		ScrollingBarVertical_=y-45;
	}
}


void UserInterface::FileMenu_check(int mouseX, int mouseY, LeoGraphics* leo)
{
	if (enableFileButton_==1)
	{
		if (mouseX>=FileMenuPosition_[0] && mouseX<=FileMenuPosition_[2] &&
			mouseY>=FileButtonPosition_[1] && mouseY<=FileMenuPosition_[3])
		{
			if (mouseY<=FileMenuPosition_[1]) {}
			else if (mouseY<=51) {
				enableFileButton_=0;
				UserInterface::OpenFile_do(leo);
			}
			else if (mouseY<=73) {
				enableFileButton_=0;
				UserInterface::Full3dLung_do(leo);
			}
			else if (mouseY<=94) {
				enableFileButton_=0;
				UserInterface::CTSlices_do(leo);
			}
			else if (mouseY<=116) {
				enableFileButton_=0;
				UserInterface::BronchialTree_do(leo);
			}
			else if (mouseY<=137) {
				enableFileButton_=0;
				UserInterface::DynamicLung_do();
			}
			else {
				exit(1);
			}
		}
		else
		{
			enableFileButton_=0;
		}
	}
}

void UserInterface::HelpMenu_check(int mouseX, int mouseY)
{
	if (enableHelpButton_==1)
	{
		if (mouseX>=HelpMenuPosition_[0] && mouseX<=HelpMenuPosition_[2] &&
			mouseY>=HelpButtonPosition_[1] && mouseY<=HelpMenuPosition_[3])
		{
			if (mouseY<=HelpMenuPosition_[1]) {}
			else if (mouseY<=55) {
				enableHelpButton_=0;
				UserInterface::ViewHelp_do();
			}
			else {
				enableHelpButton_=0;
				UserInterface::AboutUs_do();
			}
		}
		else
		{
			enableHelpButton_=0;
		}
	}
}


void UserInterface::OpenFile_do (LeoGraphics* leo)
{
	//Open Dialog
	OPENFILENAME openFileDialog;
	char szFileName[MAX_PATH]="";
	ZeroMemory(&openFileDialog, sizeof(openFileDialog));
	openFileDialog.lStructSize= sizeof(openFileDialog);
	openFileDialog.hwndOwner = hwnd;
	openFileDialog.lpstrFilter = L"RAW Files (*.RAW)\0*.RAW\0";
	openFileDialog.lpstrFile = LPWSTR(szFileName);
	openFileDialog.nMaxFile = MAX_PATH;
	openFileDialog.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
	openFileDialog.lpstrDefExt = L"RAW";
 
	if(GetOpenFileName(&openFileDialog)){
		string s="";
		for(int i = 0; i<MAX_PATH;  i++)
		{
			if(szFileName[i] == 0) continue;
			s+= szFileName[i];
		}
		leo->Read(s, hwnd, hInst);
	}
}

void UserInterface::Full3dLung_do(LeoGraphics* leo)
{
	leo->changeAlgorithm(1, hwnd, hInst);
}

void UserInterface::CTSlices_do(LeoGraphics* leo)
{
	if(!leo->canRender)
	{
		MessageBox(NULL,L"Please load RAW data first!",L"Info",MB_OK|MB_ICONEXCLAMATION);
		return;
	}
	else
	{
		leo->canDraw=false;
		leo->viewSlices=true;
	}
}

void UserInterface::BronchialTree_do(LeoGraphics* leo)
{
	leo->changeAlgorithm(0, hwnd, hInst);
}

void UserInterface::DynamicLung_do()
{
	MessageBox(NULL,L"Sorry, Work in Progress!",L"View Dynamic Lung",MB_OK|MB_ICONEXCLAMATION);
}

void UserInterface::PlayButton_do(LeoGraphics* leo)
{
	leo->autoRot=true;
}

void UserInterface::PauseButton_do(LeoGraphics* leo)
{
	leo->autoRot=false;
}

void UserInterface::BackButton_do(LeoGraphics* leo)
{
	leo->RotationDirection=1;
}

void UserInterface::NextButton_do(LeoGraphics* leo)
{
	leo->RotationDirection=3;
}

void UserInterface::UpButton_do(LeoGraphics* leo)
{
	leo->RotationDirection=4;
}

void UserInterface::DownButton_do(LeoGraphics* leo)
{
	leo->RotationDirection=2;
}

void UserInterface::FileButton_do()
{
	enableFileButton_=1;
}

void UserInterface::HelpButton_do()
{
	enableHelpButton_=1;
}

void UserInterface::ViewHelp_do()
{
	MessageBox(NULL,L"HELP\n\nView 3D lung\nThis allows the user to see a 3D image of the loaded file.\nIt is possible to rotate the image using the arrows below the image display.\nIt is also possible to see a rotating image of the image by clicking on the play button, the pause button will stop the image rotating.\n\nView CT slices\nThis allows the user to view the original CT data images of the lung, in different slices.\nThe scroll bar allows the user to view the entire collection of images.\n\nView Bronchial Tree\nThis allows the user to see through the lung, viewing the internal structure of the bronchial tree.\nIt is possible to rotate the image using the arrows below the image display.\nIt is also possible to see a rotating image of the image by clicking on the play button, the pause button will stop the image rotating.\n\nView dynamic lung\nThis part of the programme is still in process, but it will allow the user to view a dynamic model of the loaded CT files.",L"Help",MB_OK|MB_ICONEXCLAMATION);
}
void UserInterface::AboutUs_do()
{
	MessageBox(NULL,L"MengLung\nVersion 0.1\nCopyright 2011 The Hamlyn Centre, Imperial College\n\nThis programme has been created by a team of four incredibly intelligent and creative individuals. Menglong Ye, Edoardo Lopez, Samaneh Khaleghi and Alexandra Magill are all currently researching in the field of Medical Robotics and Image Guided Intervention.\n\nFor further information please contact menglong.ye11@imperial.ac.uk",L"About Us",MB_OK|MB_ICONEXCLAMATION);
}